package com.sgb.kjwl.view.ui.adapter.home;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import androidx.core.util.Pair;

import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ItemHomeServicePropertyBinding;
import com.sgb.kjwl.model.entity.enterprise.PropertyEntity;
import com.sgb.kjwl.utils.ActivityJump;
import com.sgb.kjwl.utils.PointUtils;
import com.sgb.kjwl.view.ui.activity.enterprise.MakeOverDetailActivity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class HomePropertyAdapter extends BaseRecycleAdapter<PropertyEntity> {


    public HomePropertyAdapter(Context context, List<PropertyEntity> datas) {
        super(context, R.layout.item_home_service_property, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, PropertyEntity propertyEntity) {
        ItemHomeServicePropertyBinding binding = (ItemHomeServicePropertyBinding) holder.getmBinding();
        binding.setViewModel(propertyEntity);
        TextView tv_tag = holder.getItem().findViewById(R.id.tv_item_intel_prop_publish);
        switch (propertyEntity.getPublishType()) {
            case 0://个人
                tv_tag.setText("个人");
                tv_tag.setBackgroundResource(R.drawable.shape_radius_1_solid_bule);
                break;
            case 1://企业
                tv_tag.setText("企业");
                tv_tag.setBackgroundResource(R.drawable.shape_radius_1_solid_bule);
                break;
            case 2://团队
                tv_tag.setText("团队");
                tv_tag.setBackgroundResource(R.drawable.ractangle_radius_1_solid_yellow);
                break;
            default:
                tv_tag.setVisibility(View.GONE);
                break;
        }
        binding.tvItemTradeType.setText(TextUtils.isEmpty(propertyEntity.getTypeName()) ? "/" : propertyEntity.getTypeName());
        binding.tvItemRatePayType.setText(propertyEntity.getBuyingPrice() > 0 ? PointUtils.price(propertyEntity.getBuyingPrice()) + "元" : "/");
        binding.price.setText(propertyEntity.getSalePrice() != -1 ? "¥" + PointUtils.price(propertyEntity.getSalePrice()) : "议价");
        holder.itemView.setOnClickListener(v -> ActivityJump.jumpToActivity(context, MakeOverDetailActivity.class, Pair.create("detail", "资产"), Pair.create("id", propertyEntity.getId())));
    }
}
